<html><head><title>VertexAnimation.pb</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">;   PureBasic - VertexAnimation
</font><font color="#006666">;
</font><font color="#006666">;    (c) Fantaisie Software
</font><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">; shapekey.mesh + shapekey.material done by blendman, thanks :)
</font>
<font color="#006666">;Use [PageUp] and [PageDown]
</font>
<b><font color="#006666">IncludeFile</font></b> <font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Screen3DRequester.pb"

<b><font color="#006666">Define</font></b>.f MouseX, MouseY, Pose 

<font color="#924B72">#Mesh</font> = 1

<b><font color="#006666">Macro</font></b> <font color="#006666">Clamp</font>(num, min, max)
  <b><font color="#006666">If</font></b> num&#060;min
    num=min
  <b><font color="#006666">ElseIf</font></b> num&#062;max
    num=max
  <b><font color="#006666">EndIf</font></b>  
<b><font color="#006666">EndMacro</font></b>

<b><font color="#006666">If</font></b> <font color="#006666">InitEngine3D</font>(3)
    
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Textures", <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Models", <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Scripts", <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Packs/desert.zip", <font color="#924B72">#PB_3DArchive_Zip</font>)
<font color="#006666">  Parse3DScripts</font>()
  
<font color="#006666">  InitSprite</font>()
<font color="#006666">  InitKeyboard</font>()
<font color="#006666">  InitMouse</font>()
  
  <b><font color="#006666">If</font></b> <font color="#006666">Screen3DRequester</font>()
    
<font color="#006666">    WorldShadows</font>(<font color="#924B72">#PB_Shadow_Modulative</font>)
    
    <font color="#006666">;Ground
</font>    <font color="#006666">;
</font><font color="#006666">    CreateMaterial</font>(0,<font color="#006666"> LoadTexture</font>(0, "Dirt.jpg"))
<font color="#006666">    CreatePlane</font>(0, 1500, 1500, 40, 40, 15, 15)
<font color="#006666">    CreateEntity</font>(0,<font color="#006666">MeshID</font>(0),<font color="#006666">MaterialID</font>(0))
    
    <font color="#006666">;- Mesh
</font>    
<font color="#006666">    LoadMesh</font>(<font color="#924B72">#Mesh</font>, "Shapekey.mesh")
    
    <font color="#006666">; Create a animation state For each vertex pose, using the pose name 
</font>    Track     = 0 
    KeyFrame  = 0 
    PoseIndex = 0
    Animation$ =<font color="#006666"> MeshPoseName</font>(<font color="#924B72">#Mesh</font>, PoseIndex)
    
<font color="#006666">    CreateVertexAnimation</font>(<font color="#924B72">#Mesh</font>, Animation$, 0)                 <font color="#006666">; Create animation just for this pose
</font><font color="#006666">    CreateVertexTrack</font>(<font color="#924B72">#Mesh</font>, Animation$, Track)                 <font color="#006666">; Create track for this pose
</font><font color="#006666">    CreateVertexPoseKeyFrame</font>(<font color="#924B72">#Mesh</font>, Animation$, Track, KeyFrame)<font color="#006666">; Create a keyframe for this pose.
</font>        
    <font color="#006666">;- Entity
</font><font color="#006666">    CreateEntity</font>(1,<font color="#006666"> MeshID</font>(<font color="#924B72">#Mesh</font>), <font color="#924B72">#PB_Material_None</font>, 0, 50, 0)
<font color="#006666">    ScaleEntity</font>(1, 3, 3, 3)
<font color="#006666">    StartEntityAnimation</font>(1, Animation$)  
   
    <font color="#006666">;- SkyBox
</font><font color="#006666">    SkyBox</font>("Desert07.jpg")
    
    <font color="#006666">;- Camera
</font><font color="#006666">    CreateCamera</font>(0, 0, 0, 100, 100)
<font color="#006666">    MoveCamera</font>(0, 10,<font color="#006666"> EntityY</font>(1) + 4, -10, <font color="#924B72">#PB_Absolute</font>)
<font color="#006666">    CameraLookAt</font>(0,<font color="#006666"> EntityX</font>(1),<font color="#006666"> EntityY</font>(1),<font color="#006666"> EntityZ</font>(1))
    
    <font color="#006666">;- Light
</font><font color="#006666">    CreateLight</font>(0,<font color="#006666"> RGB</font>(255, 255, 255), -40, 100, 80)
<font color="#006666">    AmbientColor</font>(<font color="#006666">RGB</font>(80, 80, 80))
     
    <b><font color="#006666">Repeat</font></b>
<font color="#006666">      Screen3DEvents</font>()
      
      <b><font color="#006666">If</font></b> <font color="#006666">ExamineMouse</font>()
        MouseX = -<font color="#006666">MouseDeltaX</font>()/10 
        MouseY = -<font color="#006666">MouseDeltaY</font>()/10
      <b><font color="#006666">EndIf</font></b>
      
      <b><font color="#006666">If</font></b> <font color="#006666">ExamineKeyboard</font>()
        
        <b><font color="#006666">If</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_PageDown</font>) <b><font color="#006666">And</font></b> Pose &#060; 1
          Pose + 0.01
<font color="#006666">          Clamp</font>(Pose, 0, 1)
        <b><font color="#006666">ElseIf</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_PageUp</font>) <b><font color="#006666">And</font></b> Pose &#062; 0
          Pose - 0.01
<font color="#006666">          Clamp</font>(Pose, 0, 1) 
        <b><font color="#006666">EndIf</font></b>
        
      <b><font color="#006666">EndIf</font></b>
      
      <font color="#006666">; update the pose reference
</font><font color="#006666">      UpdateVertexPoseReference</font>(<font color="#924B72">#Mesh</font>, Animation$, Track, KeyFrame, PoseIndex, Pose)
      
      <font color="#006666">; update animation state since we're fudging this manually
</font><font color="#006666">      UpdateEntityAnimation</font>(1, Animation$)
      
<font color="#006666">      RotateCamera</font>(0, MouseY, MouseX, 0, <font color="#924B72">#PB_Relative</font>)
      
<font color="#006666">      RenderWorld</font>() 
      
<font color="#006666">      FlipBuffers</font>()
    <b><font color="#006666">Until</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>) <b><font color="#006666">Or</font></b> Quit = 1
  <b><font color="#006666">EndIf</font></b>
  
<b><font color="#006666">Else</font></b>
<font color="#006666">  MessageRequester</font>("Error", "The 3D Engine can't be initialized",0)
<b><font color="#006666">EndIf</font></b>

<b><font color="#006666">End</font></b></font></pre>
</body></html>
